package com.parking.mgr.useraccount.controller;

import com.parking.mgr.common.annotion.BusinessLog;
import com.parking.mgr.common.pojo.response.Result;
import com.parking.mgr.useraccount.service.ParkingRecordFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName ParkingRecordFileController
 * @Description TODO
 * @author: puyunqing
 * @Date: 2025/3/7
 */
@Log4j2
@Api(value = "停车备案文件上传", tags = {"停车备案文件上传"})
@RequestMapping("/api/parking/record/file")
@RestController
public class ParkingRecordFileController {

    @Resource
    private ParkingRecordFileService parkingRecordFileService;

    @PostMapping("/application/form/uploadFile")
    @ApiOperation(value = "上传停车场审批申请表", notes = "上传停车场审批申请表", httpMethod = "POST")
    @BusinessLog(title = "上传停车场审批申请表")
    public Result<?> uploadApplicationFormFile(@RequestParam("file") MultipartFile file,
                                     @ApiParam(name = "fkParkingRecordId", value = "停车备案信息表ID")
                                     @RequestParam(value = "fkParkingRecordId", required = false) String fkParkingRecordId,
                                     HttpServletRequest request) {
        parkingRecordFileService.uploadApplicationFormFile(file, fkParkingRecordId, request);
        return Result.success();
    }

    @PostMapping("/management/system/uploadFile")
    @ApiOperation(value = "上传停车场管理制度", notes = "上传停车场管理制度", httpMethod = "POST")
    @BusinessLog(title = "上传停车场管理制度")
    public Result<?> uploadManagementSystemFile(@RequestParam("file") MultipartFile file,
                                     @ApiParam(name = "fkParkingRecordId", value = "停车备案信息表ID")
                                     @RequestParam(value = "fkParkingRecordId", required = false) String fkParkingRecordId,
                                     HttpServletRequest request) {
        parkingRecordFileService.uploadManagementSystemFile(file, fkParkingRecordId, request);
        return Result.success();
    }

    @PostMapping("/use/certification/uploadFile")
    @ApiOperation(value = "上传有效的实地使用证明材料", notes = "上传有效的实地使用证明材料", httpMethod = "POST")
    @BusinessLog(title = "上传有效的实地使用证明材料")
    public Result<?> uploadUseCertificationFile(@RequestParam("file") MultipartFile file,
                                                @ApiParam(name = "fkParkingRecordId", value = "停车备案信息表ID")
                                                @RequestParam(value = "fkParkingRecordId", required = false) String fkParkingRecordId,
                                                HttpServletRequest request) {
        parkingRecordFileService.uploadUseCertificationFile(file, fkParkingRecordId, request);
        return Result.success();
    }

    @PostMapping("/fire/certificate/uploadFile")
    @ApiOperation(value = "上传消防合格证明", notes = "上传消防合格证明", httpMethod = "POST")
    @BusinessLog(title = "上传消防合格证明")
    public Result<?> uploadFireCertificateFile(@RequestParam("file") MultipartFile file,
                                              @ApiParam(name = "fkParkingRecordId", value = "停车备案信息表ID")
                                              @RequestParam(value = "fkParkingRecordId", required = false) String fkParkingRecordId,
                                              HttpServletRequest request) {
        parkingRecordFileService.uploadFireCertificateFile(file, fkParkingRecordId, request);
        return Result.success();
    }

    @PostMapping("/id/card/entrust/file/uploadFile")
    @ApiOperation(value = "上传法人、责任人、办理人身份证明、企业授权经办人委托书", notes = "上传法人、责任人、办理人身份证明、企业授权经办人委托书", httpMethod = "POST")
    @BusinessLog(title = "上传法人、责任人、办理人身份证明、企业授权经办人委托书")
    public Result<?> uploadIdCardEntrustFile(@RequestParam("file") MultipartFile file,
                                              @ApiParam(name = "fkParkingRecordId", value = "停车备案信息表ID")
                                              @RequestParam(value = "fkParkingRecordId", required = false) String fkParkingRecordId,
                                              HttpServletRequest request) {
        parkingRecordFileService.uploadIdCardEntrustFile(file, fkParkingRecordId, request);
        return Result.success();
    }

    @PostMapping("/parking/diagram/env/uploadFile")
    @ApiOperation(value = "上传车场平面示意图及现状环境照片", notes = "上传车场平面示意图及现状环境照片", httpMethod = "POST")
    @BusinessLog(title = "上传车场平面示意图及现状环境照片")
    public Result<?> uploadParkingDiagramEnvFile(@RequestParam("file") MultipartFile file,
                                                   @ApiParam(name = "fkParkingRecordId", value = "停车备案信息表ID")
                                                   @RequestParam(value = "fkParkingRecordId", required = false) String fkParkingRecordId,
                                                   HttpServletRequest request) {
        parkingRecordFileService.uploadParkingDiagramEnvFile(file, fkParkingRecordId, request);
        return Result.success();
    }

    @PostMapping("/completion/accept/record/uploadFile")
    @ApiOperation(value = "上传竣工验收备案表", notes = "上传竣工验收备案表", httpMethod = "POST")
    @BusinessLog(title = "上传竣工验收备案表")
    public Result<?> uploadCompletionAcceptRecordFile(@RequestParam("file") MultipartFile file,
                                                  @ApiParam(name = "fkParkingRecordId", value = "停车备案信息表ID")
                                                  @RequestParam(value = "fkParkingRecordId", required = false) String fkParkingRecordId,
                                                  HttpServletRequest request) {
        parkingRecordFileService.uploadCompletionAcceptRecordFile(file, fkParkingRecordId, request);
        return Result.success();
    }

    @PostMapping("/process/plan/uploadFile")
    @ApiOperation(value = "上传停车场突发事件处理预案", notes = "上传停车场突发事件处理预案", httpMethod = "POST")
    @BusinessLog(title = "上传停车场突发事件处理预案")
    public Result<?> uploadProcessPlan(@RequestParam("file") MultipartFile file,
                                       @ApiParam(name = "fkParkingRecordId", value = "停车备案信息表ID")
                                       @RequestParam(value = "fkParkingRecordId", required = false) String fkParkingRecordId,
                                       HttpServletRequest request) {
        parkingRecordFileService.uploadProcessPlan(file, fkParkingRecordId, request);
        return Result.success();
    }

    @PostMapping("/charge/publicity/uploadFile")
    @ApiOperation(value = "上传停车场收费公示牌", notes = "上传停车场收费公示牌", httpMethod = "POST")
    @BusinessLog(title = "上传停车场收费公示牌")
    public Result<?> uploadChargePublicity(@RequestParam("file") MultipartFile file,
                                       @ApiParam(name = "fkParkingRecordId", value = "停车备案信息表ID")
                                       @RequestParam(value = "fkParkingRecordId", required = false) String fkParkingRecordId,
                                       HttpServletRequest request) {
        parkingRecordFileService.uploadChargePublicity(file, fkParkingRecordId, request);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation(value = "上传文件列表", notes = "上传文件列表", httpMethod = "GET")
    @BusinessLog(title = "上传文件列表")
    public Result<?> fileList(@ApiParam(name = "fkParkingRecordId", value = "停车备案信息表ID")
                              @RequestParam(value = "fkParkingRecordId", required = false) String fkParkingRecordId,
                              HttpServletRequest request) {
        return Result.success(parkingRecordFileService.getUrl(fkParkingRecordId));
    }

}
